package com.example.demo.controller;

import com.example.demo.controller.data.ReturnData;
import com.example.demo.service.UploadService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 上传文件相关的接口控制类
 */
@RestController
public class UploadController {

    @Resource
    UploadService uploadService;

    /**
     * 上传头像的接口
     * @param id
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("uploadAvtar")
    public ReturnData uploadAvtar(int id, MultipartFile file) throws IOException {
        return uploadService.uploadAvtar(id,file);
    }

    /**
     * 上传文件接口
     * @param type 用来区分不同业务的文件: 1头像 2朋友圈的图片 3文章图片 4轮播图图片 5个人背景图
     * @param file 上传的文件
     * @return
     * @throws IOException
     */
    @PostMapping("uploadFile")
    public ReturnData uploadFile(int type, MultipartFile file) throws IOException {
        return uploadService.uploadFile(type,file);
    }



}
